import java.util.ArrayList;
import java.util.List;

/**
 * Prime Factors exercise from TW101 Module 1
 *
 * Created by dmorti on 12/02/14.
 */
public class PrimeFactorsExercise {
    public static void main(String[] args) {
        PrimeFactorsExercise exercise = new PrimeFactorsExercise();

        System.out.println("1 has no prime factors: ");
        System.out.println(exercise.generate(1).toString());

        System.out.println("The prime factors of 30 are: ");
        System.out.println(exercise.generate(30).toString());
    }

    private List<Integer> generate(int n) {
        List<Integer> factors = new ArrayList<Integer>();

        int trialFactor = 2;

        while(n > 1) {
            if (n % trialFactor == 0) {
                factors.add(trialFactor);
                n = n/trialFactor;
            } else trialFactor++;
        }

        return factors;
    }
}
